import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Form, Input } from 'antd'

// 添加分类的form组件
export default class AddForm extends Component {
  state = {
    categoryName: this.props.categoryName
  }
  static propTypes = {
    categoryName: PropTypes.string,
    setName: PropTypes.func
  }

  changeName = (event) => {
    this.props.setName(event.target.value)
  }
  render() {
    const { categoryName } = this.state
    return (
      <Form validateTrigger="onChange">
        <Form.Item
          rules={[{ required: true, message: '输入内容分类名称！' }]}
        >
          <Input 
            onChange={this.changeName} 
            defaultValue={categoryName} 
            placeholder="请输入分类名称" 
          />
        </Form.Item>
      </Form>
    )
  }
}
